#include "StdAfx.h"
#include "Parallelogram.h"

CParallelogram::CParallelogram(void)
{
}

CParallelogram::CParallelogram(UINT type,CPoint pt)
{
	m_DrawType=type;
	Point=pt;
	PrePoint=pt;
	Height=80;
	Width=120;
	m_point1.x = pt.x - (Width+40)/2;
	m_point1.y = pt.y - Height/2;
	m_point2.x = pt.x;
	m_point2.y = pt.y - Height/2;
	m_point3.x = pt.x + (Width+40)/2;
	m_point3.y = pt.y - Height/2;
	m_point4.x = pt.x + (Width+40)/2;
	m_point4.y = pt.y;
	m_point5.x = pt.x + (Width+40)/2;
	m_point5.y = pt.y + Height/2;
	m_point6.x = pt.x;
	m_point6.y = pt.y + Height/2;
	m_point7.x = pt.x - (Width+40)/2;
	m_point7.y = pt.y + Height/2;
	m_point8.x = pt.x - (Width+40)/2;
	m_point8.y = pt.y;
}

void CParallelogram::Draw(CDC *pDC)
{
	CPoint pt[4];
	
	pt[0]=CPoint(3*m_point1.x/4+m_point3.x/4,m_point1.y);
	pt[1]=m_point3;
	pt[2]=CPoint(3*m_point5.x/4+m_point7.x/4,m_point5.y);
	pt[3]=m_point7;
	pDC->Polygon(pt,4);
}


CPoint CParallelogram::GetPoint()
{
	return Point;
}

UINT CParallelogram::GetType()
{
	return m_DrawType;
}

void CParallelogram::SetPrePoint(CPoint pt)
{
	PrePoint=pt;
}

CPoint CParallelogram::GetPrePoint()
{
	return PrePoint;
}

void CParallelogram::Move(CDC * pDC,CPoint pt)
{
	CPoint ptr[4];

	ptr[0]=CPoint(3*m_point1.x/4+m_point3.x/4,m_point1.y);
	ptr[1]=m_point3;
	ptr[2]=CPoint(3*m_point5.x/4+m_point7.x/4,m_point5.y);
	ptr[3]=m_point7;
	pDC->Polygon(ptr,4);

	Point = Point + pt-PrePoint;
	m_point1 = m_point1 + pt - PrePoint;
	m_point2 = m_point2 + pt - PrePoint;
	m_point3 = m_point3 + pt - PrePoint;
	m_point4 = m_point4 + pt - PrePoint;	
	m_point5 = m_point5 + pt - PrePoint;
	m_point6 = m_point6 + pt - PrePoint;
	m_point7 = m_point7 + pt - PrePoint;
	m_point8 = m_point8 + pt - PrePoint;

	ptr[0]=CPoint(3*m_point1.x/4+m_point3.x/4,m_point1.y);
	ptr[1]=m_point3;
	ptr[2]=CPoint(3*m_point5.x/4+m_point7.x/4,m_point5.y);
	ptr[3]=m_point7;
	pDC->Polygon(ptr,4);
	PrePoint = pt;
}


UINT CParallelogram::GetHeight()
{
	return Height;
}
UINT CParallelogram::GetWidth()
{
	return Width;
}

void CParallelogram::SetWH()
{
	Width = 3*(m_point3.x-m_point1.x)/4;
	Height = m_point7.y - m_point1.y;
}
void CParallelogram::Resize(CDC *pDC,CPoint pt,int f)
{
	CPoint ptr[4];

	ptr[0]=CPoint(3*m_point1.x/4+m_point3.x/4,m_point1.y);
	ptr[1]=m_point3;
	ptr[2]=CPoint(3*m_point5.x/4+m_point7.x/4,m_point5.y);
	ptr[3]=m_point7;
	pDC->Polygon(ptr,4);

	Change(pt,f);

	ptr[0]=CPoint(3*m_point1.x/4+m_point3.x/4,m_point1.y);
	ptr[1]=m_point3;
	ptr[2]=CPoint(3*m_point5.x/4+m_point7.x/4,m_point5.y);
	ptr[3]=m_point7;
	pDC->Polygon(ptr,4);

}

CParallelogram::~CParallelogram(void)
{
}
